from flask import Flask, jsonify

from helper import is_isbn_or_key
from yushu_book import YuShuBook

app = Flask(__name__)


@app.route('/book/search/<q>/<page>')
def search(q, page):
    isbn_or_key = is_isbn_or_key(q)

    if isbn_or_key == 'isbn':
        res = YuShuBook.search_by_isbn(q)
    else:
        res = YuShuBook.keyword_url(q)
    return jsonify(res)

@app.route('/')
def index():
    return 'hello hello'

if __name__ == '__main__':
    app.run(debug=True, port=82)
